from selenium.webdriver.common.by import By

from base.mp.base_page import BasePage, BaseOperate

"""
前台登录页面
"""


class LoginPage(BasePage):
    def __init__(self):
        super().__init__()
        self.mobile = By.CSS_SELECTOR, ".el-input__inner"
        self.code = By.XPATH, "//*[@placeholder='验证码']"
        self.login_btn = By.CSS_SELECTOR, ".el-button--primary"

    def find_mobile_box(self):
        return self.get_element(self.mobile)

    def find_code_box(self):
        return self.get_element(self.code)

    def find_login_btn(self):
        return self.get_element(self.login_btn)


class LoginOperate(BaseOperate):
    def __init__(self):
        self.lp = LoginPage()

    def input_mobile(self, mobile):
        self.input_text(self.lp.find_mobile_box(), mobile)

    def input_code(self, code):
        self.input_text(self.lp.find_code_box(), code)

    def click_login_btn(self):
        self.lp.find_login_btn().click()
        # 有bug需要点两次登录
        self.lp.find_login_btn().click()


class LoginBusiness:
    def __init__(self):
        self.op = LoginOperate()

    def login(self, mobile, code):
        self.op.input_mobile(mobile)
        self.op.input_code(code)
        self.op.click_login_btn()
